﻿/**
 * Reboulder - Partial Boulder Dash clone
 * Jesús Sagra, 2014
 * 
 * Sptrite class: basic graphic element to inherit from
 * 
 * Version    Date     Changes
 * -----------------------------------------------------
 *  0.01   06-mar-2015  Attributes, Getters, draw sprites.                
 *  0.02   06-mar-2015  Methods: CollisionsWith , Move.
 */

class Sprite
{
    public int X { get; set; }
    public int Y{ get; set; }
    public Image SpriteImage { get; set; }
    public int Height { get; set; }
    public int Width { get; set; }
    public int Speed { get; set; }
    public bool Falling { get; set; }   //falling or static state
    public bool Round { get; set; }
    public bool Visible { get; set; }
    public bool Crossable { get; set; }

    public Sprite(int x ,int y)
    {
        X = x;
        Y = y;
        Height = Width = 32;
        Visible = true;
    }


    public bool CollisionsWith(Sprite otherSprite)
    {
        return (Visible && otherSprite.Visible &&
            CollisionsWith(otherSprite.X, otherSprite.Y,
                otherSprite.X + otherSprite.Width,
                otherSprite.Y + otherSprite.Height));
    }
    

    public bool CollisionsWith(int xStart, int yStart, int xEnd, int yEnd)
    {
        return (Visible &&
            (X < xEnd) && (X + Width > xStart) &&
            (Y < yEnd) && (Y + Height > yStart));
    }


    public void DrawOnHiddenScreen()
    {
        if (Visible)
            SdlHardware.DrawHiddenImage(SpriteImage, X, Y);
    }


    public virtual void MoveDown()
    {
        Y += Speed;
    }


    public virtual void MoveUp()
    {
        Y -= Speed;
    }


    public virtual void MoveLeft()
    {
        X -= Speed;
    }


    public virtual void MoveRight()
    {
        X += Speed;
    }
}